home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / bench / RCS / client.c,v < prev    next >
Text File  |  1989-01-04  |  13KB  |  601 lines

  1. head     1.6;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    ; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.6
  10. date     89.01.04.15.36.27;  author david;  state Exp;
  11. branches ;
  12. next     1.5;
  13.  
  14. 1.5
  15. date     88.09.29.17.02.23;  author david;  state Exp;
  16. branches ;
  17. next     1.4;
  18.  
  19. 1.4
  20. date     87.12.22.10.15.33;  author brent;  state Exp;
  21. branches ;
  22. next     1.3;
  23.  
  24. 1.3
  25. date     87.07.14.10.27.03;  author brent;  state Exp;
  26. branches ;
  27. next     1.2;
  28.  
  29. 1.2
  30. date     87.05.01.15.51.58;  author brent;  state Exp;
  31. branches ;
  32. next     1.1;
  33.  
  34. 1.1
  35. date     87.04.01.10.41.22;  author brent;  state Exp;
  36. branches ;
  37. next     ;
  38.  
  39.  
  40. desc
  41. @Client code to use pseudo devices to synchronize with a server process.
  42. @
  43.  
  44.  
  45. 1.6
  46. log
  47. @Convert to machine dependent format and prints SPUR cache controller
  48. register results.
  49. @
  50. text
  51. @/* 
  52.  * client.c --
  53.  *
  54.  *    The client part of some multi-program synchronization primatives.
  55.  *    The routines here interface to the server; initial contact,
  56.  *    waiting for the start message, and notification of completion.
  57.  *
  58.  * Copyright 1986 Regents of the University of California
  59.  * All rights reserved.
  60.  */
  61.  
  62. #ifndef lint
  63. static char rcsid[] = "$Header: client.c,v 1.5 88/09/29 17:02:23 david Exp $ SPRITE (Berkeley)";
  64. #endif not lint
  65.  
  66.  
  67. #include "sprite.h"
  68. #include "status.h"
  69. #include "sys/ioctl.h"
  70. #include "sys/file.h"
  71. #include "stdio.h"
  72.  
  73. extern char *pdev;
  74. extern int errno;
  75.  
  76. char buffer[4096];
  77. int bufSize = sizeof(buffer);
  78.  
  79. typedef struct ClientState {
  80.     int clientStreamID;
  81. } ClientState;
  82.  
  83. /*
  84.  *----------------------------------------------------------------------
  85.  *
  86.  * ClientSetup --
  87.  *
  88.  *    Establish contact with the server.
  89.  *
  90.  * Results:
  91.  *    A pointer to state about the clients needed by ClientStart and
  92.  *    ClientDone.
  93.  *
  94.  * Side effects:
  95.  *    Creates named pipes and communicates with server
  96.  *    This exits upon error.
  97.  *
  98.  *----------------------------------------------------------------------
  99.  */
  100.  
  101. void
  102. ClientSetup(dataPtr)
  103.     ClientData *dataPtr;
  104. {
  105.     ClientState *statePtr;
  106.     ReturnStatus status;
  107.  
  108.     statePtr = (ClientState *)malloc(sizeof(ClientState));
  109.  
  110.     statePtr->clientStreamID = open(pdev, O_RDWR, 0);
  111.     if (statePtr->clientStreamID < 0) {
  112.     Stat_PrintMsg(errno, "ClientSetup: error opening pseudo device");
  113.     fflush(stderr);
  114.     exit(errno);
  115.     }
  116.     *dataPtr = (ClientData)statePtr;
  117. }
  118.  
  119. /*
  120.  *----------------------------------------------------------------------
  121.  *
  122.  * ClientRead --
  123.  *
  124.  *    Read from a pseudo-device.  The amount and number of repetitions
  125.  *    can be varied for measurment.
  126.  *
  127.  * Results:
  128.  *    None
  129.  *
  130.  * Side effects:
  131.  *    None.
  132.  *
  133.  *----------------------------------------------------------------------
  134.  */
  135.  
  136. void
  137. ClientRead(data, size, reps)
  138.     ClientData data;
  139.     int size;
  140.     int reps;
  141. {
  142.     ClientState *statePtr;
  143.     int amountRead;
  144.     ReturnStatus status;
  145.     char *buffer = (char *)malloc(size);
  146.  
  147.     statePtr = (ClientState *)data;
  148.     do {
  149.     amountRead = read(statePtr->clientStreamID, buffer, size);
  150.     if (amountRead < 0) {
  151.         Stat_PrintMsg(errno, "ClientRead: error on read");
  152.         break;
  153.     } if (amountRead != size) {
  154.         fprintf(stderr, "Short read %d < %d\n", amountRead, size);
  155.     }
  156.     } while (--reps > 0);
  157.     free(buffer);
  158. }
  159.  
  160. /*
  161.  *----------------------------------------------------------------------
  162.  *
  163.  * ClientWrite --
  164.  *
  165.  *    Write from a pseudo-device.  The amount and number of repetitions
  166.  *    can be varied for measurment.
  167.  *
  168.  * Results:
  169.  *    None
  170.  *
  171.  * Side effects:
  172.  *    None.
  173.  *
  174.  *----------------------------------------------------------------------
  175.  */
  176.  
  177. void
  178. ClientWrite(data, size, reps)
  179.     ClientData data;
  180.     int size;
  181.     int reps;
  182. {
  183.     ClientState *statePtr;
  184.     int amountWrite;
  185.     ReturnStatus status;
  186.     char *buffer = (char *)malloc(size);
  187.  
  188.     statePtr = (ClientState *)data;
  189.     do {
  190.         amountWrite = write(statePtr->clientStreamID, buffer, size);
  191.     if (amountWrite < 0) {
  192.         Stat_PrintMsg(errno, "ClientWrite: error on read");
  193.         break;
  194.     } if (amountWrite != size) {
  195.         fprintf(stderr, "Short write %d < %d\n", amountWrite,
  196.                     size);
  197.     }
  198.     } while (--reps > 0);
  199.     free(buffer);
  200. }
  201.  
  202. /*
  203.  *----------------------------------------------------------------------
  204.  *
  205.  * ClientIOControl --
  206.  *
  207.  *    Do an IOControl to a pseudo-device.
  208.  *    The amount of data passed in and number of repetitions
  209.  *    can be varied for measurment.
  210.  *
  211.  * Results:
  212.  *    None
  213.  *
  214.  * Side effects:
  215.  *    None.
  216.  *
  217.  *----------------------------------------------------------------------
  218.  */
  219.  
  220. void
  221. ClientIOControl(data, size, reps)
  222.     ClientData data;
  223.     int size;
  224.     int reps;
  225. {
  226.     ClientState *statePtr;
  227.     ReturnStatus status;
  228.     Address inBuffer = (Address)malloc(size);
  229.     Address outBuffer = (Address)malloc(size);
  230.     int foo = 27;
  231.  
  232.     statePtr = (ClientState *)data;
  233.     do {
  234.     /*
  235.     status = Fs_IOControl(statePtr->clientStreamID, foo, size, inBuffer,
  236.                 size, outBuffer);
  237.     */
  238.     if (status != SUCCESS) {
  239.         Stat_PrintMsg(status, "ClientIOControl: error ");
  240.         break;
  241.     }    } while (--reps > 0);
  242.     free(inBuffer);
  243.     free(outBuffer);
  244. }
  245.  
  246. /*
  247.  *----------------------------------------------------------------------
  248.  *
  249.  * ClientDone --
  250.  *
  251.  *    Tell the server we're done.  This is just done by closing
  252.  *    the pseudo stream.
  253.  *
  254.  * Results:
  255.  *    None
  256.  *
  257.  * Side effects:
  258.  *    None
  259.  *
  260.  *----------------------------------------------------------------------
  261.  */
  262.  
  263. void
  264. ClientDone(data)
  265.     ClientData data;
  266. {
  267.     ClientState *statePtr;
  268.     ReturnStatus status;
  269.  
  270.     statePtr = (ClientState *)data;
  271.     status = close(statePtr->clientStreamID);
  272.     if (status != SUCCESS) {
  273.     Stat_PrintMsg(status, "ClientDone: error on close");
  274.     }
  275. }
  276. @
  277.  
  278.  
  279. 1.5
  280. log
  281. @Converted to new libraries.
  282. @
  283. text
  284. @d13 1
  285. a13 1
  286. static char rcsid[] = "$Header: client.c,v 1.4 87/12/22 10:15:33 brent Exp $ SPRITE (Berkeley)";
  287. @
  288.  
  289.  
  290. 1.4
  291. log
  292. @removed some lint.
  293. @
  294. text
  295. @d13 1
  296. a13 1
  297. static char rcsid[] = "$Header: client.c,v 1.3 87/07/14 10:27:03 brent Exp $ SPRITE (Berkeley)";
  298. d19 3
  299. a21 3
  300. #include "io.h"
  301. #include "fs.h"
  302. #include "mem.h"
  303. d24 1
  304. d58 1
  305. a58 1
  306.     statePtr = (ClientState *)Mem_Alloc(sizeof(ClientState));
  307. d60 5
  308. a64 6
  309.     status = Fs_Open(pdev, FS_READ|FS_WRITE, 0,
  310.                  &statePtr->clientStreamID);
  311.     if (status != SUCCESS) {
  312.     Stat_PrintMsg(status, "ClientSetup: error opening pseudo device");
  313.     Io_Flush(io_StdErr);
  314.     Proc_Exit(status);
  315. d95 1
  316. a95 1
  317.     char *buffer = (char *)Mem_Alloc(size);
  318. d99 3
  319. a101 3
  320.     status = Fs_Read(statePtr->clientStreamID, size, buffer, &amountRead);
  321.     if (status != SUCCESS) {
  322.         Stat_PrintMsg(status, "ClientRead: error on read");
  323. d104 1
  324. a104 1
  325.         Io_PrintStream(io_StdErr, "Short read %d < %d\n", amountRead, size);
  326. d107 1
  327. a107 1
  328.     Mem_Free(buffer);
  329. d136 1
  330. a136 1
  331.     char *buffer = (char *)Mem_Alloc(size);
  332. d140 3
  333. a142 3
  334.     status = Fs_Write(statePtr->clientStreamID, size, buffer, &amountWrite);
  335.     if (status != SUCCESS) {
  336.         Stat_PrintMsg(status, "ClientWrite: error on read");
  337. d145 1
  338. a145 1
  339.         Io_PrintStream(io_StdErr, "Short write %d < %d\n", amountWrite,
  340. d149 1
  341. a149 1
  342.     Mem_Free(buffer);
  343. d178 2
  344. a179 2
  345.     Address inBuffer = Mem_Alloc(size);
  346.     Address outBuffer = Mem_Alloc(size);
  347. d184 1
  348. d187 1
  349. d192 2
  350. a193 2
  351.     Mem_Free(inBuffer);
  352.     Mem_Free(outBuffer);
  353. d221 1
  354. a221 1
  355.     status = Fs_Close(statePtr->clientStreamID);
  356. @
  357.  
  358.  
  359. 1.3
  360. log
  361. @Updated to handle new pseudo-device interface
  362. @
  363. text
  364. @d13 1
  365. a13 1
  366. static char rcsid[] = "$Header: client.c,v 1.2 87/05/01 15:51:58 brent Exp $ SPRITE (Berkeley)";
  367. d21 1
  368. a92 1
  369.     int client;
  370. a133 1
  371.     int client;
  372. a176 2
  373.     int client;
  374.     int amountRead;
  375. d178 3
  376. a180 2
  377.     char *inBuffer = (char *)Mem_Alloc(size);
  378.     char *outBuffer = (char *)Mem_Alloc(size);
  379. d184 1
  380. a184 1
  381.     status = Fs_IOControl(statePtr->clientStreamID, 27, size, inBuffer,
  382. @
  383.  
  384.  
  385. 1.2
  386. log
  387. @Changed over to use pseudo-dev interface instead of named pipes.
  388. @
  389. text
  390. @d13 1
  391. a13 1
  392. static char rcsid[] = "$Header: client.c,v 1.1 87/02/17 15:10:35 brent Exp $ SPRITE (Berkeley)";
  393. d22 1
  394. a22 1
  395. extern char *devBench;
  396. d58 1
  397. a58 1
  398.     status = Fs_Open(devBench, FS_READ|FS_WRITE, 0,
  399. d71 1
  400. a71 1
  401.  * ClientStart --
  402. d73 2
  403. a74 3
  404.  *    Synchronize with the server by doing our first operation on
  405.  *    the pseudo device.  The server will wait until all clients have
  406.  *    generated their requests before letting any one of them complete.
  407. d86 1
  408. a86 1
  409. ClientStart(data)
  410. d88 2
  411. d95 1
  412. a95 2
  413.     int len;
  414.     char buffer[20];
  415. d97 29
  416. a125 4
  417.     /*
  418.      * A read is done here, but it doesn't much matter what we do.
  419.      * The server is just waiting for contact from us indicating we are ready.
  420.      */
  421. d127 12
  422. a138 1
  423.     len = sizeof(buffer);
  424. d140 11
  425. a150 5
  426.     status = Fs_Read(statePtr->clientStreamID, len, buffer, &amountRead);
  427.     if (status != SUCCESS) {
  428.     Stat_PrintMsg(status, "ClientStart: error on read");
  429.     Proc_Exit(status);
  430.     }
  431. d156 43
  432. d201 1
  433. a201 1
  434.  *    Tell the server we're done.  This is just done by writing to
  435. a217 1
  436.     int amountWritten;
  437. a218 2
  438.     int len;
  439.     char buffer[20];
  440. a219 1
  441.     len = sizeof(buffer);
  442. d221 1
  443. a221 1
  444.     status = Fs_Write(statePtr->clientStreamID, len, buffer, &amountWritten);
  445. d223 1
  446. a223 1
  447.     Stat_PrintMsg(status, "ClientDone: error writing done message");
  448. @
  449.  
  450.  
  451. 1.1
  452. log
  453. @Initial revision
  454. @
  455. text
  456. @d2 1
  457. a2 1
  458.  * slave.c --
  459. d4 2
  460. a5 2
  461.  *    The slave part of some multi-program synchronization primatives.
  462.  *    The routines here interface to the master; initial contact,
  463. d13 1
  464. a13 1
  465. static char rcsid[] = "$Header: slave.c,v 1.1 87/02/17 15:10:35 brent Exp $ SPRITE (Berkeley)";
  466. d18 1
  467. d22 1
  468. a22 1
  469. extern char *masterPipe;
  470. d27 3
  471. a29 7
  472. char slavePipeName[80 + sizeof("hello\n")] = "hello\n";
  473.  
  474. typedef struct SlaveState {
  475.     int masterPipeID;
  476.     int slavePipeID;
  477.     char *slavePipeName;
  478. } SlaveState;
  479. d34 1
  480. a34 1
  481.  * SlaveSetup --
  482. d36 1
  483. a36 1
  484.  *    Establish contact with the master.
  485. d39 2
  486. a40 2
  487.  *    A pointer to state about the slaves needed by SlaveStart and
  488.  *    SlaveDone.
  489. d43 1
  490. a43 1
  491.  *    Creates named pipes and communicates with master
  492. d50 1
  493. a50 1
  494. SlaveSetup(dataPtr)
  495. d53 1
  496. a53 3
  497.     SlaveState *statePtr;
  498.     int slave;
  499.     int amountWritten;
  500. a54 2
  501.     int pid;
  502.     int len;
  503. d56 1
  504. a56 1
  505.     statePtr = (SlaveState *)Mem_Alloc(sizeof(SlaveState));
  506. d58 2
  507. a59 2
  508.     status = Fs_Open(masterPipe, FS_WRITE|FS_NAMED_PIPE_OPEN, 0,
  509.                  &statePtr->masterPipeID);
  510. d61 1
  511. a61 1
  512.     Stat_PrintMsg(status, "Error opening master pipe");
  513. a64 29
  514.     /*
  515.      * Generate a unique slave pipe name.  The "hello" message is
  516.      * stuck in front of the pipe name for an atomic write.
  517.      */
  518.     Proc_GetIDs(&pid, NULL, NULL, NULL);
  519.     String_Cat("/tmp/slave.", slavePipeName);
  520.     len = String_Length(slavePipeName);
  521.     Cvt_ItoA(pid, 10, &slavePipeName[len]);
  522.     len = String_Length("hello\n");
  523.     statePtr->slavePipeName = &slavePipeName[len];
  524.  
  525.     status = Fs_Open(statePtr->slavePipeName,
  526.              FS_CREATE|FS_READ|FS_NAMED_PIPE_OPEN,
  527.              0666, &statePtr->slavePipeID);
  528.     if (status != SUCCESS) {
  529.     Stat_PrintMsg(status, "Error opening slave pipe");
  530.     Proc_Exit(status);
  531.     }
  532.     /*
  533.      * Write both the "hello" message and the name of our pipe.
  534.      */
  535.     status = Fs_Write(statePtr->masterPipeID, sizeof(slavePipeName),
  536.                          slavePipeName, &amountWritten);
  537.     if ((status != SUCCESS) ||
  538.     (amountWritten != sizeof(slavePipeName))) {
  539.     Stat_PrintMsg(status, "Error writing master pipe");
  540.     Io_Flush(io_StdErr);
  541.     Proc_Exit(status);
  542.     }
  543. d71 1
  544. a71 1
  545.  * SlaveStart --
  546. d73 3
  547. a75 1
  548.  *    Wait for a start message from the master.
  549. d81 1
  550. a81 1
  551.  *    The start message is read from the slave's pipe.
  552. d87 1
  553. a87 1
  554. SlaveStart(data)
  555. d90 2
  556. a91 2
  557.     SlaveState *statePtr;
  558.     int slave;
  559. d95 1
  560. d97 10
  561. a106 6
  562.     len = sizeof("start\n") - 1;
  563.     statePtr = (SlaveState *)data;
  564.     status = Fs_Read(statePtr->slavePipeID, len, buffer, &amountRead);
  565.     if (status != SUCCESS ||
  566.     (String_NCompare(len, "start\n", buffer) != 0)) {
  567.     Stat_PrintMsg(status, "Error reading start command");
  568. a108 7
  569.     /*
  570.      * Remove the slave's pipe.  It appears that whenever this is
  571.      * is done it is likely to be serviced on the server during the benchmark.
  572.      * It would be possible to have another command, SlaveCleanup,
  573.      * that a master used to call back to slaves to tidy up.
  574.      */
  575.     Fs_Remove(statePtr->slavePipeName);
  576. d114 1
  577. a114 1
  578.  * SlaveDone --
  579. d116 2
  580. a117 1
  581.  *    Tell the master we're done.
  582. d123 1
  583. a123 1
  584.  *    Writes the stop message to the pipe.
  585. d129 1
  586. a129 1
  587. SlaveDone(data)
  588. d132 1
  589. a132 2
  590.     SlaveState *statePtr;
  591.     int slave;
  592. d136 1
  593. d138 5
  594. a142 5
  595.     len = sizeof("done\n") - 1;
  596.     statePtr = (SlaveState *)data;
  597.     status = Fs_Write(statePtr->masterPipeID, len, "done\n", &amountWritten);
  598.     if (status != SUCCESS || amountWritten != len) {
  599.     Stat_PrintMsg(status, "Error writing done message");
  600. @
  601.